#============================================
# #知识点
from multiprocessing import JoinableQueue,Process
import time
import random
def producer(dl,name,food):
    for i in range(1000):
        # time.sleep(random.randint(1,2))
        data = f"{name}做了{i}份{food}"
        print(data)
        dl.put(data)

def sonsumer(dl,name):
    while True:
        data = dl.get()
        # time.sleep(random.randint(1,2))
        print(f"{name}吃了{data}")
        dl.task_done()      #告诉你从队列中取了一个数据，并且处理完了-1

if __name__ == "__main__":
    dl = JoinableQueue()  #每Put一次内部计数器+1
    obj1 = Process(target=producer,args=(dl,"小黑","热干面"))
    obj2 = Process(target=sonsumer,args=(dl,"小白"))  
    obj2.daemon = True
    obj1.start()
    obj2.start()
    obj1.join()
    dl.join()      #等待所有队列得数据被取完  才能执行下面得代码（也就是计数器为0的时候）
    print('========================')
#============================================